package com.ants.logic.app.listener;

import com.alibaba.fastjson.JSON;
import com.ants.logic.app.dto.DecreaseStorageDto;
import com.ants.logic.app.feign.StorageFeignService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 蚂蚁会花呗
 * @date 2021/12/2 15:28
 * 扣减库存消息监听，消费者
 */
@Component
@RocketMQMessageListener(topic = "my-topic",consumerGroup = "my-group")
@Slf4j
public class StorageConsumer implements RocketMQListener<String> {

    @Autowired
    private StorageFeignService storageFeignService;


    @Override
    public void onMessage(String s) {
        log.info("消费消息：" + s);
        /**
         * 消费消息，远程调用库存系统
         */
        storageFeignService.decreaseStorage(JSON.toJavaObject(JSON.parseObject(s), DecreaseStorageDto.class));
    }
}
